package com.changhongit.service.wemeet;

import com.changhongit.utils.RequestSenderUtil;
import com.changhongit.vo.InviteesMeetingVo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tencentcloudapi.wemeet.client.MeetingClient;
import com.tencentcloudapi.wemeet.common.exception.WemeetSdkException;
import com.tencentcloudapi.wemeet.models.BaseResponse;
import com.tencentcloudapi.wemeet.models.meeting.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MeetingService {
    private static final Log log = LogFactory.getLog(MeetingService.class);
    private static final Gson GSON = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
    @Autowired
    RequestSenderUtil sender;

    /**
     * 创建会议
     * @param request
     * @return
     * @throws WemeetSdkException
     */
    public QueryMeetingDetailResponse createMeeting(CreateMeetingRequest request) throws WemeetSdkException {
        MeetingClient meetingClient = new MeetingClient(sender.getProfile());
        QueryMeetingDetailResponse response = meetingClient.createMeeting(request);
        log.info(GSON.toJson(response));
        return response;
    }

    //设置会议邀请成员
    public void inviteesMeetin(InviteesMeetingVo inviteesMeetingVo) throws WemeetSdkException{
        MeetingClient meetingClient = new MeetingClient(sender.getProfile());
        InviteesMeetingRequest request=new InviteesMeetingRequest();
        request.setMeetingId(inviteesMeetingVo.getMeeting_id());
        request.setInstanceId(inviteesMeetingVo.getInstanceid());
        request.setUserId(inviteesMeetingVo.getUserid());
        List<InviteesMeetingRequest.InviteUser> inviteUserList=new ArrayList<>();

        for (com.changhongit.pojo.meeting.InviteUser user :inviteesMeetingVo.getInvites()) {
            InviteesMeetingRequest.InviteUser inviteUser = new InviteesMeetingRequest.InviteUser();
            inviteUser.setUserId(user.getUserid());
            inviteUserList.add(inviteUser);
        }

        request.setInvitees(inviteUserList);
        

        BaseResponse response = meetingClient.inviteesMeeting(request);
        log.info(GSON.toJson(response));
    }
    //获取会议受邀成员列表
    public QueryInviteesMeetingUserResponse queryInviteesMeetingUserResponse(QueryInviteesMeetingUserRequest request) throws WemeetSdkException{
        MeetingClient meetingClient = new MeetingClient(sender.getProfile());
        QueryInviteesMeetingUserResponse response = meetingClient.queryInviteesMeetingUserResponse(request);
        log.info(GSON.toJson(response));
        return response;
    }



}